local sk__guicai = fk.CreateSkill {

  name = "sk__guicai",

  tags = {},

}



sk__guicai:addEffect(fk.AskForRetrial, {
  name = "sk__guicai",
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(sk__guicai.name)
  end,
  on_cost = function(self, event, target, player, data)
    local extra_data = {
      num = 1,
      min_num = 0,
      include_equip = false,
      skillName = sk__guicai.name,
      pattern = ".",
    }
    local success, dat = player.room:askForUseActiveSkill(player, "choose_cards_skill",
      "#sk__guicai-invoke::" .. target.id, true, extra_data)
    if success then
      event:setCostData(self, dat~=nil and dat.cards or {})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if #event:getCostData(self) > 0 then
      room:changeJudge({
        card = Fk:getCardById(event:getCostData(self)[1]),
        player = player,
        data = data,
        skillName = sk__guicai.name,
      })
    else
      local move1 = {
        ids = room:getNCards(1),
        toArea = Card.Processing,
        moveReason = fk.ReasonJustMove,
        skillName = sk__guicai.name,
        proposer = player,
      }
      local move2 = {
        ids = { data.card:getEffectiveId() },
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonJustMove,
        skillName = sk__guicai.name,
      }
      room:moveCards(move1, move2)
      data.card = Fk:getCardById(move1.ids[1])
      room:sendLog {
        type = "#ChangedJudge",
        from = player.id,
        to = { player.id },
        card = { move1.ids[1] },
        arg = sk__guicai.name
      }
    end
  end,
})

return sk__guicai
